﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Find most frequent number</title>
    <link href="styles/js-console.css" rel="stylesheet" />
</head>
<body>
    <div id="js-console"></div>
	<script src="scripts/js-console.js"></script>
	<script>
	    var arr = [2, -2, 4, 6, -3, 2, 7, 6, 8, 9, 2];
	    var count = 1;
	    var max = 1;
	    var mostFrequent;
	    var currentFrequent;
	    for (var i = 0; i < arr.length; i++) {
	        currentFrequent = arr[i];
	        count = 1;
	        for (var j = i + 1; j < arr.length; j++) {
	            if (currentFrequent == arr[j]) {
	                count++;
	                if (count > max) {
	                    max = count;
	                    mostFrequent = arr[i];
	                }
	            }
	        }
	    }
	    if (max == 1) {
	        jsConsole.writeLine("There isn`t most frequently number!");
	    }
	    else {
	        jsConsole.writeLine("The most frequently number is: " + mostFrequent + "(" + max + " times)");
	    }
    </script>
</body>
</html>
